package com.paradogs.common.utils;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * @author: yumi
 * @date: 2023/7/26  17:34
 * @Description: 事件发布订阅工具
 */
@Component
public class EventUtils implements ApplicationEventPublisherAware {

    /** Spring 事件发布机制 */
    private static ApplicationEventPublisher applicationEventPublisher;

    /** 发布事件: 订阅事件由 Spring 的 @EventListener 注册 */
    public static void publishEvent(ApplicationEvent event) {
        applicationEventPublisher.publishEvent(event);
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        EventUtils.applicationEventPublisher = applicationEventPublisher;
    }

}
